# database class

from sqlite3 import dbapi2 as sqlite
import sort_history
import os

class db_object:
    
    conn = sqlite.connect
    #initialize with a database file
    def _init(sqlite_file):
        
        #connect to sqlite file
        if os.path.isfile(sqlite_file):
            conn = sqlite.connect(sqlite_file)
            conn.row_factory = sqlite.Row
            conn.text_factory = sqlite.OptimizedUnicode
            return True
        
        # method to create the database
        # if file is csv data
        
        #bad file
    
    #update the database
    def update_db(date, first, second, third, fourth, fifth, power):
        conn.execute('INSERT INTO history values (?, ?, ?, ?, ?, ?)', [date, first, second, third, fourth, fifth])
        last_date = sort_history.get_last_row(dates)
        new_index = last_date[0] + 1
        conn.execute('insert into dates values (?,?)', [new_index,date])
        
        return
    
    
